import defaultSettings from "@/settings";
import request from "@/utils/request";

export const apiUrlConfig = {
  queryUrl: `${defaultSettings.ctx.batchApp}/s/scubbConf/search`,
  exportUrl: `${defaultSettings.ctx.batchApp}/s/scubbConf/search`,
  delUrl: `${defaultSettings.ctx.batchApp}/s/scubbConf/remove`,
}

/**
 * 保存工作流程
 * @param data
 * @returns {AxiosPromise}
 */
export function save(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/addFlowConf`,
    method: 'post',
    data: data
  })
}

export function queryAllFlowConf(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/queryAllFlowConf`,
    method: 'get',
    data: data
  })
}

/**
 * 获取工作流程详情
 * @param data
 * @returns {AxiosPromise}
 */
export function get(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/findFlowConfById`,
    method: 'get',
    params: {
      id: data
    }
  })
}

/**
 * 修改工作流程
 * @param data
 * @returns {AxiosPromise}
 */
export function update(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/modifyFlowConf`,
    method: 'post',
    data: data
  })
}

/**
 * 删除一个工作流程
 * @param ids
 * @returns {AxiosPromise}
 */
export function del(ids) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/removeFlowConf`,
    method: 'get',
    params: {
      ids: ids
    }
  })
}

export function checkFlowCodeUnique(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/checkFlowCodeUnique`,
    method: 'post',
    data
  })
}

export function checkFlowNameUnique(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/checkFlowNameUnique`,
    method: 'post',
    data
  })
}

/**
 * 获取工作流程的JSON信息
 * @param data
 * @returns {AxiosPromise}
 */
export function getWorkflowJson(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/queryFlowData`,
    method: 'get',
    params: {
      id: data
    }
  })
}

/***
 * 修改工作流程的JSON配置
 * @param data
 * flowId
 * flowCode
 * editorData
 * @returns {AxiosPromise}
 */
export function updateWorkflowJson(data) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/saveFlowConfig`,
    method: 'post',
    data
  })
}


/**
 * 测试接口
 * @param flowCode
 * @param requestNo
 * @returns {AxiosPromise}
 */
export function testRun(flowCode,requestNo) {
  return request({
    url: `${defaultSettings.ctx.batchApp}/s/scubbConf/testRun`,
    method: 'post',
    data: {
      requestNo: requestNo,
      flowCode: flowCode
    }
  })
}
